package com.hongning.railway.ui.main.fragments.college;

import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hongning.railway.R;
import com.hongning.railway.app.AppViewModelFactory;
import com.hongning.railway.databinding.FragmentCollegeExamCompleteBinding;
import com.hongning.railway.databinding.FragmentCollegeExamUncompleteBinding;
import com.hongning.railway.util.Apputils;

import me.goldze.mvvmhabit.BR;
import me.goldze.mvvmhabit.base.BaseFragment;

public class ExamUnCompleteFragment extends BaseFragment<FragmentCollegeExamUncompleteBinding,ExamUnCompleteFragmentViewModel> {
    public static ExamUnCompleteFragment newInstance() {

        Bundle args = new Bundle();

        ExamUnCompleteFragment fragment = new ExamUnCompleteFragment();
        fragment.setArguments(args);
        return fragment;
    }
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_college_exam_uncomplete;
    }

    @Override
    public ExamUnCompleteFragmentViewModel initViewModel() {
        AppViewModelFactory appViewModelFactory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this,appViewModelFactory).get(ExamUnCompleteFragmentViewModel.class);
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        binding.includeAppstatus.ivStatu.setImageResource(R.mipmap.icon_nocontent);
        binding.includeAppstatus.tvStatu.setText("暂无内容");
        Apputils.setDefaultHeaderView(binding.trRefhreh);
        binding.rvContent.setItemAnimator(null);
        viewModel.loadExamListData();
    }

    @Override
    public void initViewObservable() {
        viewModel.uc.finishRefresh.observe(this, new Observer() {
            @Override
            public void onChanged(@Nullable Object o) {
                binding.trRefhreh.finishRefreshing();
                binding.trRefhreh.setEnableLoadmore(true);
            }
        });

        viewModel.uc.finishLoadMore.observe(this, new Observer() {
            @Override
            public void onChanged(@Nullable Object o) {
                binding.trRefhreh.finishLoadmore();
            }
        });
        viewModel.uc.contentEmpty.observe(this, new Observer() {
            @Override
            public void onChanged(@Nullable Object o) {
                binding.includeAppstatus.rlContent.setVisibility(View.VISIBLE);
            }
        });
        viewModel.uc.finishLoadMoreEnd.observe(this, new Observer() {
            @Override
            public void onChanged(@Nullable Object o) {
                binding.trRefhreh.setEnableLoadmore(false);
            }
        });

    }
}
